package com.authine.cloudpivot.ext.utils;

import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.function.BiFunction;


public class CalculatorUtils {

    public static <T> BigDecimal sum(List<T> params, BiFunction<T, BigDecimal, BigDecimal> function) {

        BigDecimal result = BigDecimal.ZERO;

        if (CollectionUtils.isEmpty(params)) {
            return result;
        }
        for (T param : params) {
            result = function.apply(param, result);
        }

        return result;
    }

}
